package hardwareToSQL;


public class Separator {

	/**The length of the separator */
	private int length;
	/**The symbol representing the separator */
	private String symbol;
	/**Buffer storing bytes that will be compared to as a string to the
	 * separator to see if one has been received from the socket */
	private char[] symbolArray;

	
	/**Class constructor. Set the symbol representing the separator
	 * and its corresponding length */
	public Separator(int length, String symbol){
		this.length  = length;
		this.symbol = symbol;
		symbolArray = symbol.toCharArray();
	}

	/**Take a new character from input and check if the last set
	 * of characters form the required separator */
	public boolean update(char dataByte) {
		for(int i=0; i< length-1; i++) {
			symbolArray[i] = symbolArray[i+1];
		}
		symbolArray[length-1] = dataByte;
		if(symbol.equals(new String(symbolArray))){
			return true;
		} else {
			return false;
		}
	}
	
	/**Return the current values stored in this object */
	public char[] returnSymbol(){
		return symbolArray;
	}

}
